package com.edu.exam.enums.examination;

import com.edu.exam.enums.core.BaseEnum;

import java.util.Arrays;

/**
 * 答案状态枚举
 *
 * <p>定义考试中学生答案的状态，包括草稿、已保存、已修改、已提交等状态。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum AnswerStatus implements BaseEnum {

    /** 草稿 */
    DRAFT("DRAFT", "草稿", "答案正在编辑中，尚未正式保存"),

    /** 已保存 */
    SAVED("SAVED", "已保存", "答案已正式保存，可以继续修改"),

    /** 已修改 */
    MODIFIED("MODIFIED", "已修改", "已保存的答案被修改，需要重新保存"),

    /** 最终 */
    FINAL("FINAL", "最终", "答案已确认不再修改"),

    /** 已提交 */
    SUBMITTED("SUBMITTED", "已提交", "答案已提交，无法再修改"),

    /** 自动保存 */
    AUTO_SAVED("AUTO_SAVED", "自动保存", "系统自动保存的答案"),

    /** 待确认 */
    PENDING("PENDING", "待确认", "答案修改后需要确认保存"),

    /** 同步中 */
    SYNCING("SYNCING", "同步中", "答案正在与服务器同步"),

    /** 已锁定 */
    LOCKED("LOCKED", "已锁定", "答案被锁定，暂时无法修改"),

    /** 已验证 */
    VERIFIED("VERIFIED", "已验证", "答案已通过格式验证"),

    /** 评分中 */
    GRADING("GRADING", "评分中", "答案正在评阅过程中"),

    /** 已评分 */
    GRADED("GRADED", "已评分", "答案已评阅完成，有评分结果"),

    /** 已阅卷 */
    REVIEWED("REVIEWED", "已阅卷", "答案已通过教师阅卷确认");

    private final String code;
    private final String description;
    private final String detail;

    AnswerStatus(String code, String description, String detail) {
        this.code = code;
        this.description = description;
        this.detail = detail;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public String getDetail() {
        return detail;
    }

    public static AnswerStatus fromCode(String code) {
        return Arrays.stream(values())
                .filter(e -> e.getCode().equals(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unknown answer status code: " + code));
    }
    @Override
    public String toString() {
        return description;
    }
}